<template>
  <el-card class="box-card">
    {{ editing }}
    {{ map.size }}
    <el-form
      :model="ruleForm"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      {{ current }}
      <el-form-item label="span" prop="span">
        <el-input-number
          :value="current.span"
          @input="
            (val) => {
              set('span', val);
            }
          "
        ></el-input-number>
      </el-form-item>
      <el-form-item>
        <el-button @click="set()">重置</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >修改</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item> -->
    </el-form>
  </el-card>
</template>
<script>
import Vue from "vue";
import { mapState } from "vuex";

export default {
  name: "QPropertyEdit",
  data() {
    return {
      ruleForm: {
        name: "",
      },
    };
  },
  methods: {
    set(field, val) {
      if (Object.keys(this.current).includes(field)) {
        this.current[field] = val;
      } else {
        console.log('current')
        Vue.set(this.current, field, val);
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  computed: {
    ...mapState({
      editing: (state) => state.prop.editing,
      map: (state) => state.prop.map,
    }),
    current() {
      return this.map.has(this.editing) ? this.map.get(this.editing) : {};
    },
  },
};
</script>
<style scoped>
.box-card {
  width: 300px;
}
</style>
